import logging

from autoadmin.lib.base import *
from autoadmin.lib.finder import ModelFinderError

from autoadmin.model import Session

log = logging.getLogger(__name__)

class ListController(BaseController):

    def index(self, model_name):
        
        try:
            model_class = g.model_finder.get_model(model_name)
        except ModelFinderError, error:
            self.log.exception(error)
            return error.message
        
        c.model_name = model_name
        c.objects = Session.query(model_class).filter_by().all()
        
        return render('/list.mako')
